/* QtLua -- Lua bindings for Qt
   Copyright (C) 2011, Jarek Pelczar

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 3 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General
   Public License along with this library; if not, write to the
   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301 USA

*/

#ifndef WRAP_QSIZE_H
#define WRAP_QSIZE_H

#include <QObject>
#include <QSize>
#include "qluascriptable.h"
#include "qluascriptengine.h"
#include "qluascriptvalue.h"
#include "qluascriptclass.h"
#include "qluaglobal.h"

class QSize_Prototype : public QObject, public QLuaScriptable
{
    Q_OBJECT
    Q_INTERFACES(QLuaScriptable)
    Q_PROPERTY(int width READ getWidth WRITE setWidth)
    Q_PROPERTY(int height READ getHeight WRITE setHeight)
public:
    QSize_Prototype(QObject * parent = 0);

public slots:
    bool isNull() const;
    bool isEmpty() const;
    bool isValid() const;

    int getWidth() const;
    int getHeight() const;
    void setWidth(int x);
    void setHeight(int y);

    QSizeF toSizeF() const;

    void transpose();

    void scale(int w, int h, int mode);
    void scale(const QSize &s, int mode);

    QSize expandedTo(const QSize &) const;
    QSize boundedTo(const QSize &) const;

private:
    QSize * ptr() const;
};

class QSizeF_Prototype : public QObject, public QLuaScriptable
{
    Q_OBJECT
    Q_INTERFACES(QLuaScriptable)
    Q_PROPERTY(qreal width READ getWidth WRITE setWidth)
    Q_PROPERTY(qreal height READ getHeight WRITE setHeight)
public:
    QSizeF_Prototype(QObject * parent = 0);

public slots:
    bool isNull() const;
    bool isEmpty() const;
    bool isValid() const;

    qreal getWidth() const;
    qreal getHeight() const;
    void setWidth(qreal x);
    void setHeight(qreal y);

    QSize toSize() const;

    void transpose();

    void scale(qreal w, qreal h, int mode);
    void scale(const QSizeF &s, int mode);

    QSizeF expandedTo(const QSizeF &) const;
    QSizeF boundedTo(const QSizeF &) const;

private:
    QSizeF * ptr() const;
};

class QSize_wrapper : public QObject, public QLuaScriptClass
{
    Q_OBJECT
    Q_INTERFACES(QLuaScriptClass)
public:
    QSize_wrapper(QLuaScriptEngine * engine);

    virtual QueryFlags queryProperty(const QLuaScriptValue& object,
                                     const QByteArray& name);
    virtual QLuaScriptValue property(const QLuaScriptValue& object,
                                          const QByteArray& name);
    virtual QLuaScriptValue prototype() const;
    virtual QString name() const;

private:
    static QLuaScriptValue QSize_toScriptValue(QLuaScriptEngine * engine, const QSize * t);
    static void QSize_fromScriptValue(const QLuaScriptValue& value, QSize * t);
    static QLuaScriptValue new_size(QLuaScriptContext *, QLuaScriptEngine *);

private:
    QLuaScriptValue m_proto;
};

class QSizeF_wrapper : public QObject, public QLuaScriptClass
{
    Q_OBJECT
    Q_INTERFACES(QLuaScriptClass)
public:
    QSizeF_wrapper(QLuaScriptEngine * engine);

    virtual QueryFlags queryProperty(const QLuaScriptValue& object,
                                     const QByteArray& name);
    virtual QLuaScriptValue property(const QLuaScriptValue& object,
                                          const QByteArray& name);
    virtual QLuaScriptValue prototype() const;
    virtual QString name() const;

private:
    static QLuaScriptValue QSizeF_toScriptValue(QLuaScriptEngine * engine, const QSizeF * t);
    static void QSizeF_fromScriptValue(const QLuaScriptValue& value, QSizeF * t);
    static QLuaScriptValue new_sizeF(QLuaScriptContext *, QLuaScriptEngine *);

private:
    QLuaScriptValue m_proto;
};

#endif // WRAP_QSIZE_H
